import Vue from 'vue'
import VueRouter from 'vue-router'
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
	return originalPush.call(this, location).catch(err => err)
}


Vue.use(VueRouter)

const routes = [{
		path: '/',
		name: 'home',
		redirect: '/login',
		component: () => import('../views/Home'),
		meta: {
			title: "登录"
		},
	},
	{
		path: '/index',
		name: 'index',
		redirect: '/home',
		component: () => import('@/views/Index'),
		meta: {
			title: "首页"
		},
		children: [{
				path: '/home',
				name: 'home',
				component: () => import('@/views/Home'),
				meta: {
					title: "首页"
				}
			}, {
				path: '/goodsDetail',
				name: 'goodsDetail',
				component: () => import('@/views/GoodsDetail'),
				meta: {
					title: "商品列表"
				}
			},
			{
				path: '/goodsOperation',
				name: 'goodsOperation',
				component: () => import('@/views/GoodsOperation'),
				meta: {
					title: "商品管理"
				}
			},
			{
				path: '/orderDetail',
				name: 'orderDetail',
				component: () => import('@/views/OrderDetail'),
				meta: {
					title: "订单列表"
				}
			},
			{
				path: '/orderOPeration',
				name: 'orderOPeration',
				component: () => import('@/views/OrderOPeration'),
				meta: {
					title: "订单管理"
				}
			},
			{
				path:'/categories',
				name:'categories',
				component:()=>import('@/views/Categories'),
				meta:{
					title:'商品分类'
				}
			},
			{
				path:'/userlist',
				name:'userlist',
				component:()=>import('@/views/Userlist'),
				meta:{
					title:'用户列表'
				}
			},
			{
				path:'/adduser',
				name:'adduser',
				component:()=>import('@/views/Adduser'),
				meta:{
					title:'添加用户'
				}
				
			},
			{
				path:'/usercao',
				name:'usercao',
				component:()=>import('@/views/Usercao'),
				meta:{
					title:'用户操作'
				}
			}
		]
	},
	
	{
		path: '/login',
		name: 'login',
		component: () => import('@/views/Login'),
		meta:{
			title:'登录'
		}
	}
]

const router = new VueRouter({
	// mode: 'history',
	base: process.env.BASE_URL,
	routes
})
router.beforeEach((to,from,next)=>{
	if(to.meta.title){
		document.title=to.meta.title
	}
	next()
})
export default router
